<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class TestEvent
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    protected $channel = 'channel-event';
    public $params;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($params)
    {
        //
        $this->params = $params;
        Log::channel('event')->info('event construct params : ' . json_encode($params));
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel($this->channel);
    }

    /**
     * Execute the event.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        Log::channel('event')->info('enter handle : ' . json_encode($this->params));
        return true;
    }

}
